package cn.jja8.config.tool.work.obj.parameterized;

import cn.jja8.config.tool.work.obj.ObjKeepManager;

import java.util.HashMap;
import java.util.Map;

public class ParameterizedKeepManager {
    final ObjKeepManager objKeepManager;
    final Map<Class, ParameterizedKeep> fieldAsMap = new HashMap<>();

    public ParameterizedKeepManager(ObjKeepManager objKeepManager) {
        this.objKeepManager = objKeepManager;
        add(new FieldAsList());
        add(new FieldAsMap());
    }

    public <T> void add(ParameterizedKeep<T> basicFieldAs){
        fieldAsMap.put(basicFieldAs.Type(),basicFieldAs);
    }
    public <T> ParameterizedKeep<T> get(Class<T> type){
        return fieldAsMap.get(type);
    }

    public <T> ParameterizedKeep<T> getNoNull(Class<T> type){
        ParameterizedKeep parameterizedKeep = fieldAsMap.get(type);
        if (parameterizedKeep==null){
            throw new Error("没有找到合适的用于"+type+"的ParameterizedKeep");
        }
        return parameterizedKeep;
    }
}
